package com.iRomantic.domain.entity;

import java.sql.Timestamp;
import java.util.List;
import java.util.UUID;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

/**
 * 婚礼祝福
 * @author serenity
 *
 */
public class Bless extends Model<Bless> {
	
	private static final long serialVersionUID = -3951035472254460001L;
	
	/**
	 * 婚礼祝福类型
	 */
	public static  final String BLESS_TYPE = "0";
	
	public static final Bless DAO = new Bless();
	
	
	
	
	/**
	 * 保存
	 */
	public boolean save(){
		Long timestamp = System.currentTimeMillis();
		this.set("id", UUID.randomUUID().toString());
		this.set("createTime", new Timestamp(timestamp));
		this.set("timeStamp", timestamp.toString());
		return super.save();
	}
	
	/**
	 * 根据婚礼ID查询时间戳之前的记录
	 * @param weddingId
	 * @param tempstamp
	 * @return
	 */
	public List<Record> findBeforeTimestampByWedding(String weddingId,String tempstamp ){
		List<Record> records = Db.find("select u.*,b.* from t_bless as b ,t_user as u where b.userId=u.id and b.weddingId=? and b.timeStamp<? order by b.timeStamp desc limit 0,20 ", weddingId, tempstamp);
		return records;
	}
	
	/**
	 * 根据婚礼ID查询时间戳之后的记录
	 * @param weddingId
	 * @param tempstamp
	 * @return
	 */
	public List<Record> findAfterTimestampByWedding(String weddingId,String tempstamp){
		List<Record> records = Db.find("select u.*,b.* from t_bless as b ,t_user as u where b.userId=u.id and b.weddingId=? and b.timeStamp>? order by b.timeStamp limit 0,20 ", weddingId, tempstamp);
		return records;
	}

}
